package com.rsk.service.info.impl;


import java.util.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.dubbo.config.annotation.Service;
import com.rsk.dao.info.RskInfoTabRepository;
import com.rsk.dao.info.extend.RskInfoTabExtend;
import com.rsk.dao.utils.SearchDataUtils;
import com.rsk.entity.info.RskInfoTab;
import com.rsk.service.info.RskInfoTabService;
import com.rsk.utils.algorithm.SnowflakeIdWorker;
import com.rsk.utils.tools.PageUtils;


@Service(interfaceClass = RskInfoTabService.class)
public class RskInfoTabServiceImpl implements RskInfoTabService{
	
	@Autowired
	private RskInfoTabRepository rskInfoTabRepository;
	
    @Autowired
    private RskInfoTabExtend rskInfoTabExtend;
    
    @Autowired
    private SearchDataUtils searchDataUtils;

    @Transactional
	public int saveInfoTab(String labelName, String labelRemarks,
			Long operatorUser) {
		RskInfoTab rskInfoTab = new RskInfoTab();
		rskInfoTab.setId(SnowflakeIdWorker.generateId(true));
		rskInfoTab.setLabelName(labelName);
		rskInfoTab.setLabelRemarks(labelRemarks);
		rskInfoTab.setIsDel(0);
		rskInfoTab.setOperatorUser(operatorUser);
		rskInfoTab.setOperatorTime(new Date());
		rskInfoTabRepository.saveAndFlush(rskInfoTab);
		return 1;
	}

    @Transactional
	public int updateInfoTab(Long id, String labelName, String labelRemarks,
			Long operatorUser) {
		return rskInfoTabRepository.updateInfoTab(id, labelName, labelRemarks, operatorUser);
	}

    @Transactional
	public int delInfoTab(Long id, Long operatorUser) {
		return rskInfoTabRepository.delInfoTab(id, operatorUser);
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	public PageUtils<Map> selectInfoTabByPage(String labelName,
			Integer nowPage, Integer pageSize) {
		Map<String, Object> map = rskInfoTabExtend.selectInfoTabByPage(labelName);
        String sql = map.get("sql").toString();
        String countSQL =  map.get("countSQL").toString();
        Map<String,Object> paramMap = (Map<String, Object>) map.get("paramMap");
        PageUtils<Map> page = searchDataUtils.searchByPage(nowPage, pageSize, sql, countSQL, paramMap, Map.class);
		return page;
	}

}
